package com.LC.Controller.BKManagement;

import com.LC.Constant.MessageConstant;
import com.LC.Entity.CheckItem;
import com.LC.Entity.PageResult;
import com.LC.Entity.QueryPageBean;
import com.LC.Entity.Result;
import com.LC.Service.CheckItemService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 检查项管理
 */
@RestController
//@RequestMapping("/checkitem")
public class CheckItemController {

    @Reference //查找服务
    private CheckItemService checkItemService;
    
    @PreAuthorize("hasAuthority('CHECKITEM_ADD')")
    @RequestMapping ("/BKManagement/CheckItem")
    //@RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        try {
            checkItemService.add(checkItem);
        }catch (Exception e){
            return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
    }
    
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    @RequestMapping ("/BKManagement/CheckItem/Page")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
      PageResult pageResult = checkItemService.findPage(queryPageBean);
      return pageResult;
    }
    
    @RequestMapping("/BKManagement/CheckItem/de")
    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')") //权限校验
    public Result deleteCheckItem(Integer id){
        try {
            checkItemService.deleteById(id);
        } catch (Exception e) {
            return new Result(false,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }

    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    @RequestMapping("/BKManagement/CheckItem/dataById")
    public CheckItem itemDataById(int id){
        return checkItemService.itemById(id);
    }
    
    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")
    @RequestMapping("/BKManagement/CheckItem/update")
    public Result newItemDate(@RequestBody CheckItem checkItem){
        try { 
            checkItemService.newItemData(checkItem);
        } catch (Exception e) {
            return new Result(false,MessageConstant.EDIT_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }
}
